package groupware;
import java.util.Map; 
import java.util.HashMap;
import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.InheritanceStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.users.User;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)

public class Task{
	  @PrimaryKey
	  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	  private Key key;

	  @Persistent
	  private Key parentProject;
	  
	  @Persistent
	  private Key parentTask;
	  
	  @Persistent
	  private User owner;

	  //@Persistent
	  //Group

	  @Persistent
	  private Date creationDate;

	  @Persistent
	  private Date startDate;
	  
	  @Persistent
	  private String title;

	  @Persistent
	  private String description;

	  @Persistent
	  //add more levels
	  private boolean isPublic;
	  
	  @Persistent
	  private Date dueDate;
	  
	  @Persistent
	  private Date modificationDate;

	  //Log Class Add
	   @Persistent(serialized="true")
	   private Map<Date,String> log = new HashMap<Date,String>();
	 
	   public Task(
				  User owner,
				  //Group group,
				  String title,
			      String description, 
			      Date startDate,
			      boolean isPublic,
			      Date dueDate) {
				  
				this.owner = owner;
			    this.title = title;
			    this.description = description;
			    this.isPublic = isPublic;
			    this.dueDate = dueDate;
			    this.creationDate = new Date();
			    this.startDate = startDate;
			    this.modificationDate = this.creationDate;
			    this.log.put(creationDate, this.title+" created by: ");//+this.owner.getNickname()); 
			    
			  }

	  public Key getKey() {
	    return key;
	  }

	  public User getOwner() {
	    return owner;
	  }

	  public Date getCreationTime() {
	    return creationDate;
	  }

	  public boolean isPublic() {
	    return isPublic;
	  }

	  public String getDescription() {
	    return description;
	  }

	  public String getTitle() {
	    return title;
	  }
	  
	  public Date getDueDate() {
	    return dueDate;
	  }
	  
	  public Date getModificationDate() {
	    return modificationDate;
	  }
	  

	  public String getURLPath() {
	    String key = "2";
	    return "/resource?key=" + key;
	  }

	  public String getDisplayURL() {
	    String key = "2";
	    return "/display?key=" + key;
	  }
	  
	  public void setParentProject(Key parentKey) {
		  this.parentProject = parentKey;
	  }


	}
